package cn.geminis.warehouse.service.purchase.entity;

import cn.geminis.lowcode.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.OneToMany;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;

/**
 * 入库单
 */
@Getter
@Setter
@UuidEntity
@QueryFilter
@CrudRepository
@CrudController(save = false, delete = false)
public class Purchase {

    /**
     * 单号
     */
    @Column(length = 36)
    private String no;

    /**
     * 计划入库时间
     */
    @Column(nullable = false)
    private LocalDate planTime;

    /**
     * 总价
     */
    @Column(nullable = false)
    private BigDecimal price;

    /**
     * 发货时间
     */
    @Column
    private LocalDate deliveryTime;

    /**
     * 到货时间
     */
    @Column
    private LocalDate arriveTime;

    /**
     * 扫描时间
     */
    @Column
    private LocalDate receiveTime;

    /**
     * 质检时间
     */
    @Column
    private LocalDate checkTime;

    /**
     * 装箱时间
     */
    @Column
    private LocalDate packageTime;

    /**
     * 备注
     */
    @Column(length = 2048)
    private String memo;

    /**
     * 状态
     */
    @Column(nullable = false)
    @Convert(converter = PurchaseState.PurchaseStateJpaConverter.class)
    @QueryFilterProperty(propertyType = "cn.geminis.warehouse.service.purchase.entity.PurchaseState")
    private PurchaseState state;

    /**
     * 线路明细
     */
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "purchase")
    @JsonIgnoreProperties("purchase")
    private Set<PurchaseRoute> routes;

    /**
     * 入库单明细
     */
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "purchase")
    @JsonIgnoreProperties("purchase")
    private Set<PurchaseDetail> details;

    /**
     * 验收问题明细
     */
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "purchase")
    @JsonIgnoreProperties("purchase")
    private Set<PurchaseCheckFailed> checkFailed;

}
